home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 1992 August
/
info-mac-1992.iso
/
Source
/
3D GrafSys
/
GrafSys.rel
/
Demo Sources
/
CubeDance
next >
Wrap
Text File
|
1992-04-25
|
3KB
|
144 lines
program TestGrafSys;
{ 3d GrafSys Demo Program}
{ Vers. 1.1 }
{ (c) 1992 by Christian Franz }
{ This program demonstates the use of the grafsys for simple animation using }
{ the fDrawObject and free rotation command }
{ It also demonstrates the use of AddPoint and AddLine routines for building }
{ 3D objects }
uses
Grafsys, Screen3D;
const
theWindowID = 400;
degree = 0.01745329; (* π/180 *)
var
theWindow: WindowPtr;
theInt: INTEGER;
thePort: Graf3DPtr;
theMaster: Graf3DPtr;
Pyramid, Cube, xFighter: GrafObjPtr;
theEvent: EventRecord;
dx, dy, dz: integer;
r: Rect;
p1, p2: Vector4;
sign: integer;
procedure MakeCube (var Obj: GrafObjPtr);
var
count: INTEGER;
OK: Boolean;
begin
Obj := NewObject;
OK := AddPoint(Obj, 100, 100.0, -100, count);
OK := AddPoint(Obj, -100, 100.0, -100, count);
OK := AddPoint(Obj, -100, -100.0, -100, count);
OK := AddPoint(Obj, 100, -100.0, -100, count);
OK := AddPoint(Obj, 100, 100.0, 100, count);
OK := AddPoint(Obj, -100, 100.0, 100, count);
OK := AddPoint(Obj, -100, -100.0, 100, count);
OK := AddPoint(Obj, 100, -100.0, 100, count);
OK := AddLine(Obj, 1, 2);
OK := AddLine(Obj, 2, 3);
OK := AddLine(Obj, 3, 4);
OK := AddLine(Obj, 4, 1);
OK := AddLine(Obj, 1, 5); (* First side, no NewLine *)
OK := AddLine(Obj, 5, 6);
OK := AddLine(Obj, 6, 7);
OK := AddLine(Obj, 7, 8);
OK := AddLine(Obj, 8, 5);
OK := AddLine(Obj, 2, 6);
OK := AddLine(Obj, 3, 7);
OK := AddLine(Obj, 4, 8);
OK := AddLine(Obj, 1, 3);
OK := AddLine(Obj, 2, 4);
end;
procedure getmouserot (var dx, dy, dz: integer);
var
thePoint: point;
begin
GetMouse(thePoint);
dx := 0;
dy := 0;
dz := 0;
if (thePoint.h < thePort^.center.h) and (thePoint.v < thePort^.center.v) then (* mouse in quadrant 1 -> xrot*)
begin
dx := 5;
end;
if (thePoint.h > thePort^.center.h) and (thePoint.v < thePort^.center.v) then (* mouse in quadrant 2 -> yrot*)
begin
dy := 5;
end;
if (thePoint.h > thePort^.center.h) and (thePoint.v > thePort^.center.v) then (* mouse in quadrant 3 -> zrot*)
begin
dz := 5;
end;
if (thePoint.h < thePort^.center.h) and (thePoint.v > thePort^.center.v) then (* mouse in quadrant 4 -> idle*)
begin
end;
if button then
begin
dx := -dx;
dy := -dy;
dz := -dz;
end;
end;
begin
theWindow := GetNewWindow(theWindowID, nil, Pointer(-1));
SetPort(theWindow); (* draw in this window *)
;
{PenMode(patXOR);}
MoveTo(10, 10);
DrawString('3D Grafiksystem. Object: Cube. (C) 1991 by C. Franz');
InitGrafSys;
NewGrafport(theWindow^.portRect, thePort);
MoveTo(10, thePort^.bottom - 0);
DrawString(' Press Button to Exit');
MakeCube(cube);
SetEye(False, 0, 0, 0, 0, 0, 0, 1.512, FALSE);
ObjFreeTranslate(cube, 0, 0, 500);
ObjRotate(cube, 0 * degree, 0 * degree, 0);
ObjScale(cube, 1, 1, 1);
SetAutoErase(cube, True);
p1[1] := 0;
p1[2] := 0;
p1[3] := 400;
p2[1] := 0;
p2[2] := 200;
p2[3] := 400;
p1[4] := 1;
p2[4] := 1;
sign := 1;
fDrawObject(cube);
repeat
fDrawObject(cube);
ObjRotateArb(cube, p1, p2, 2 * degree); (* although locally done has global effect *)
ObjRotate(cube, 6 * degree, 0, 0);
until Button;
end.